﻿using System;

namespace ConsoleApplication15
{
    public struct Option<TValue>
    {
        public static readonly Option<TValue> None = new Option<TValue>();

        private readonly bool hasValue;
        private readonly TValue value;
        public Option(TValue value)
        {
            this.value = value;
            hasValue = true;
        }

        public bool HasValue
        {
            get { return hasValue; }
        }

        public TValue Value
        {
            get
            {
                if (!hasValue) throw new InvalidOperationException();
                return value;
            }
        }

        public static implicit operator Option<TValue>(TValue value)
        {
            return new Option<TValue>(value);
        }
    }
}